package part11;

import java.util.ArrayList;

/**
 * @author wcj
 * @Date 2021/5/20 16:26
 * @Version 1.0
 */
public class Part111 {

    public static void main(String[] args) {
        // 使用泛型可以避免往容器中插入错误类型的元素
        ArrayList<Apple> apples = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            apples.add(new Apple());
        }
        for (int i = 0; i < apples.size(); i++) {
            System.out.println(apples.get(i).id());
        }
        // 还能往容器中放入泛型的导出类对象
        apples.add(new BigApple());
        for (Apple a : apples) {
            System.out.println(a.id());
        }
    }
}

class Apple {
    private static long counter;
    private final long id = counter++;

    public long id() {
        return id;
    }
}

class Orange {
}

class BigApple extends Apple {
}
